<template>
  <TwoDialog id="addCustomer" v-model="showDialog" title="新增客户" width="500px" @submit="handlerSave"
    @close="handlerCancel">
    <el-form v-model="form" label-width="120px">
      <el-form-item label="邮箱">
        <el-input v-model="form.email" />
      </el-form-item>
      <el-form-item label="客户名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="客户地址">
        <el-input v-model="form.address" />
      </el-form-item>
      <el-form-item label="公司名称">
        <el-input v-model="form.company" />
      </el-form-item>
      <el-form-item label="ASI编号">
        <el-input v-model="form.asi" />
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="form.phoneNumber" />
      </el-form-item>
      <el-form-item label="官网">
        <el-input v-model="form.webUrl" />
      </el-form-item>
    </el-form>
  </TwoDialog>
</template>

<script lang="ts" setup>
import { defineProps, ref } from 'vue';
import api from '/@/api/email/index';
import { ElMessage } from 'element-plus';

defineProps({
  data: {
    type: Object,
    default: {},
  },
});

const form = ref({
  id: undefined,
  email: '',
  name: '',
  address: '',
  company: '',
  asi: '',
  phoneNumber: '',
  webUrl: '',
});
const showDialog = ref(false)

const emit = defineEmits(['close']);

const handlerCancel = () => {
  emit('close');
};

const handlerSave = async () => {
  const saveFun = form.value.id ? api.client.updateClient : api.client.addClient;
  const res = await saveFun(form.value);
  if (res.code === 200) {
    ElMessage({ type: 'success', message: '操作成功' });
    emit('close', true);
  }
};

defineExpose({
  showDialog,
  form
})
</script>
<style lang="scss" scoped></style>